#!/bin/sh
# resner@sdf.org
# simple fetch program for BSDs.

reset="\033[0m"
red="\033[0;31m"
green="\033[0;32m"
blue="\033[0;34m"
yellow="\033[0;33m"
orange="\033[38;5;208m" # requires 256 color terminal
underline="\033[4m"
bold="\033[1m"

cpu=`sysctl -n hw.model`
#cpu_ghz=`sysctl -n hw.cpuspeed | awk '{ print $0 / 1000 }'` # convert mhz to ghz, not used because the cpu name will usually include the speed.
cpu_cores=`sysctl -n hw.ncpuonline` 
vendor=`sysctl -n hw.vendor`
ram=`sysctl -n hw.physmem | awk '{ print $1 / 1073741824 }'` # convert to GB, not using let so there are decimals.
hostname=`hostname -s`
release=`uname -r`
os=`uname -s`
let uptime="($(date +%s) - $(sysctl -n kern.boottime)) / 3600" # get uptime in hours, the uptime command was more complicated to parse (at least on openbsd).

# use the operating system's main color, if nothing matches then the when the name is printed it will just be bold white.
case $os in
	OpenBSD) os_color="$yellow" ;;
	FreeBSD) os_color="$red" ;;
	NetBSD) os_color="$orange" ;;
esac	

echo -e  "	$blue$USER$reset@$red$hostname$reset on $os_color$bold$os $release$reset
-------------------------------------------------
	${bold}UPTIME$reset	:	$uptime hours
	${bold}CPU$reset	:	$cpu with $cpu_cores cores
	${bold}MEMORY$reset	:	$ram GB"
